/*
 * Created by JFormDesigner on Mon Jul 16 17:25:31 EDT 2007
 */

package antLogic;

import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;

import com.jgoodies.forms.factories.*;
import com.jgoodies.forms.layout.*;

/**
 * @author Philippe Bosse
 */
public class AntStatusPanel extends JPanel {

    AntManager owner;

    public AntStatusPanel(AntManager owner) {
        initComponents();
        this.owner = owner;
    }

    private void refreshAntDataButtonActionPerformed(ActionEvent e) {
        owner.updateStatus();
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        // Generated using JFormDesigner non-commercial license
        antIdLabel = new JLabel();
        id = new JTextField();
        antEnergyLabel = new JLabel();
        energy = new JTextField();
        antStepCountLabel = new JLabel();
        stepCount = new JTextField();
        antBearingLabel = new JLabel();
        bearing = new JTextField();
        antCurrentPathLabel = new JLabel();
        path = new JTextField();
        andNeedsToThinkLabel = new JLabel();
        think = new JTextField();
        numItemsInMemLabel = new JLabel();
        memories = new JTextField();
        label1 = new JLabel();
        position = new JTextField();
        refreshAntDataButton = new JButton();
        CellConstraints cc = new CellConstraints();

        //======== this ========
        setBorder(new TitledBorder("Ant Info"));
        setLayout(new FormLayout(
                new ColumnSpec[]{
                        new ColumnSpec(ColumnSpec.FILL, Sizes.DEFAULT, FormSpec.DEFAULT_GROW),
                        FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
                        FormFactory.DEFAULT_COLSPEC,
                        FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
                        new ColumnSpec("max(default;85dlu)"),
                        FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
                        new ColumnSpec(ColumnSpec.FILL, Sizes.DEFAULT, FormSpec.DEFAULT_GROW)
                },
                new RowSpec[]{
                        new RowSpec(RowSpec.CENTER, Sizes.DEFAULT, FormSpec.DEFAULT_GROW),
                        FormFactory.LINE_GAP_ROWSPEC,
                        FormFactory.DEFAULT_ROWSPEC,
                        FormFactory.LINE_GAP_ROWSPEC,
                        FormFactory.DEFAULT_ROWSPEC,
                        FormFactory.LINE_GAP_ROWSPEC,
                        FormFactory.DEFAULT_ROWSPEC,
                        FormFactory.LINE_GAP_ROWSPEC,
                        FormFactory.DEFAULT_ROWSPEC,
                        FormFactory.LINE_GAP_ROWSPEC,
                        FormFactory.DEFAULT_ROWSPEC,
                        FormFactory.LINE_GAP_ROWSPEC,
                        FormFactory.DEFAULT_ROWSPEC,
                        FormFactory.LINE_GAP_ROWSPEC,
                        FormFactory.DEFAULT_ROWSPEC,
                        FormFactory.LINE_GAP_ROWSPEC,
                        FormFactory.DEFAULT_ROWSPEC,
                        FormFactory.LINE_GAP_ROWSPEC,
                        FormFactory.DEFAULT_ROWSPEC,
                        FormFactory.LINE_GAP_ROWSPEC,
                        FormFactory.DEFAULT_ROWSPEC,
                        FormFactory.LINE_GAP_ROWSPEC,
                        FormFactory.DEFAULT_ROWSPEC,
                        FormFactory.LINE_GAP_ROWSPEC,
                        new RowSpec(RowSpec.CENTER, Sizes.DEFAULT, FormSpec.DEFAULT_GROW)
                }));

        //---- antIdLabel ----
        antIdLabel.setText("ID:");
        add(antIdLabel, cc.xywh(3, 3, 1, 1, CellConstraints.RIGHT, CellConstraints.FILL));

        //---- id ----
        id.setEditable(false);
        add(id, cc.xy(5, 3));

        //---- antEnergyLabel ----
        antEnergyLabel.setText("Energy Level:");
        add(antEnergyLabel, cc.xywh(3, 5, 1, 1, CellConstraints.RIGHT, CellConstraints.FILL));

        //---- energy ----
        energy.setEditable(false);
        add(energy, cc.xy(5, 5));

        //---- antStepCountLabel ----
        antStepCountLabel.setText("Step Count:");
        add(antStepCountLabel, cc.xywh(3, 7, 1, 1, CellConstraints.RIGHT, CellConstraints.FILL));

        //---- stepCount ----
        stepCount.setEditable(false);
        add(stepCount, cc.xy(5, 7));

        //---- antBearingLabel ----
        antBearingLabel.setText("Bearing:");
        add(antBearingLabel, cc.xywh(3, 9, 1, 1, CellConstraints.RIGHT, CellConstraints.FILL));

        //---- bearing ----
        bearing.setEditable(false);
        add(bearing, cc.xy(5, 9));

        //---- antCurrentPathLabel ----
        antCurrentPathLabel.setText("Current Path:");
        add(antCurrentPathLabel, cc.xywh(3, 11, 1, 1, CellConstraints.RIGHT, CellConstraints.FILL));

        //---- path ----
        path.setEditable(false);
        add(path, cc.xy(5, 11));

        //---- andNeedsToThinkLabel ----
        andNeedsToThinkLabel.setText("Needs to think:");
        add(andNeedsToThinkLabel, cc.xywh(3, 13, 1, 1, CellConstraints.RIGHT, CellConstraints.DEFAULT));

        //---- think ----
        think.setEditable(false);
        add(think, cc.xy(5, 13));

        //---- numItemsInMemLabel ----
        numItemsInMemLabel.setText("Memories:");
        add(numItemsInMemLabel, cc.xywh(3, 15, 1, 1, CellConstraints.RIGHT, CellConstraints.FILL));

        //---- memories ----
        memories.setEditable(false);
        add(memories, cc.xy(5, 15));

        //---- label1 ----
        label1.setText("Position:");
        add(label1, cc.xywh(3, 19, 1, 1, CellConstraints.RIGHT, CellConstraints.FILL));

        //---- position ----
        position.setEditable(false);
        add(position, cc.xy(5, 19));

        //---- refreshAntDataButton ----
        refreshAntDataButton.setText("Refresh");
        refreshAntDataButton.setIcon(null);
        refreshAntDataButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                refreshAntDataButtonActionPerformed(e);
            }
        });
        add(refreshAntDataButton, cc.xywh(3, 23, 3, 1));
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    // Generated using JFormDesigner non-commercial license
    private JLabel antIdLabel;
    private JTextField id;
    private JLabel antEnergyLabel;
    private JTextField energy;
    private JLabel antStepCountLabel;
    private JTextField stepCount;
    private JLabel antBearingLabel;
    private JTextField bearing;
    private JLabel antCurrentPathLabel;
    private JTextField path;
    private JLabel andNeedsToThinkLabel;
    private JTextField think;
    private JLabel numItemsInMemLabel;
    private JTextField memories;
    private JLabel label1;
    private JTextField position;
    private JButton refreshAntDataButton;
    // JFormDesigner - End of variables declaration  //GEN-END:variables

    protected void loadAntData(Ant ant, Coordinate position) {
        try {
            id.setText(ant.getAntId().toString());
        } catch (Exception e) {

        }
        try {
            energy.setText(ant.getEnergy().toString());
        } catch (Exception e) {
            energy.setText("Unknown/Undefined");
        }
        try {
            stepCount.setText(ant.stepCount.toString());
        } catch (Exception e) {
            stepCount.setText("Unknown/Undefined");
        }
        try {
            bearing.setText(ant.getBearing().toString());
        } catch (Exception e) {
            bearing.setText("Unknown/Undefined");
        }
        try {
            think.setText("" + ant.getNeedsToThink().toString());
        } catch (Exception e) {
            think.setText("Unknown");
        }
        try {
            memories.setText("" + ant.getMemory().size());
        } catch (Exception e) {
            memories.setText("Empty");
        }
        try {
            this.position.setText(position.toString());
        } catch (Exception e) {
            this.position.setText("Unknown");
        }
        try {
            path.setText(ant.legs.currentPath.getName());
        } catch (Exception e) {
            path.setText("No path");
        }
        try {
            this.position.setText(AntManager.antMgr.world.getAntPosition(ant.getAntId()).toString());
        } catch (Exception e) {
            this.position.setText("Location not known by world");
        }
    }
}
